package com.chuyu.cy.contants;

import lombok.Data;

/**
 * @author 周小白
 */
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg("success");
        result.setData(data);

        return result;
    }

    public Result<T> success() {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg("success");

        return result;
    }

    public Result<T> failure(String message) {
        Result<T> result = new Result<>();
        result.setCode(500);
        result.setMsg(message);

        return result;
    }

    public Result<T> failure(ResponseCodeEnum responseCodeEnum) {
        Result<T> result = new Result<>();
        result.setCode(responseCodeEnum.getCode());
        result.setMsg(responseCodeEnum.getMessage());

        return result;
    }
}
